package com.yangjie.web.jsf.user;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.yangjie.user.domain.User;

public class UserDataModel extends ListDataModel<User> implements SelectableDataModel<User> {

    public UserDataModel() {  
    }  
  
    public UserDataModel(List<User> data) {  
        super(data);  
    }  
    
	@Override
	public User getRowData(String rowKey) {
		List<User> users = (List<User>)getWrappedData();
		int id = Integer.parseInt(rowKey);
		for(User user:users) {
			if(user.getId() == id) {
				return user;
			}
		}
		return null;
	}

	@Override
	public Object getRowKey(User user) {
		// TODO Auto-generated method stub
		return user.getId();
	}  
	
}
